package chabernac.android.wordbattle.paint.crosstile;

import chabernac.android.wordbattle.model.Word;
import chabernac.android.wordbattle.model.WordRaster;
import chabernac.android.wordbattle.paint.DrawableComposite;
import chabernac.android.wordbattle.paint.iDrawable;
import chabernac.android.wordbattle.paint.iDrawableFactory;

public class CrossTitleWordRasterFactory implements iDrawableFactory {
	
	public CrossTitleWordRasterFactory()
	{
		super();
	}
	
	@Override
    public iDrawable createGameDrawable( WordRaster aRaster ) {
      Word aSelectedWord = new Word(aRaster.getSelectedLetters());
      DrawableComposite aDrawableCrossTileComposite = new DrawableComposite();
      // Add quarter cross tiles
      aDrawableCrossTileComposite.addDrawable(new QuarterDownRightCrossTileDrawable(aSelectedWord, aRaster.getLetter(0, 0)));
      aDrawableCrossTileComposite.addDrawable(new QuarterUpRightCrossTileDrawable(aSelectedWord, aRaster.getLetter(0, aRaster.getRows()-1)));
      aDrawableCrossTileComposite.addDrawable(new QuarterDownLeftCrossTileDrawable(aSelectedWord, aRaster.getLetter(aRaster.getColumns()-1, 0)));
      aDrawableCrossTileComposite.addDrawable(new QuarterUpLeftCrossTileDrawable(aSelectedWord, aRaster.getLetter(aRaster.getColumns()-1, aRaster.getRows()-1)));
      // Add top and bottom border
      for(int column = 0; column< aRaster.getColumns()-1; column++)
	  {
    	  aDrawableCrossTileComposite.addDrawable(new HalfDownCrossTileDrawable(aSelectedWord, aRaster.getLetter(column, 0), aRaster.getLetter(column+1, 0)));
    	  aDrawableCrossTileComposite.addDrawable(new HalfUpCrossTileDrawable(aSelectedWord, aRaster.getLetter(column, aRaster.getRows()-1), aRaster.getLetter(column+1, aRaster.getRows()-1)));
	  }
      // Add left and right border
      for(int row = 0; row< aRaster.getRows()-1; row++)
	  {
    	  aDrawableCrossTileComposite.addDrawable(new HalfRightCrossTileDrawable(aSelectedWord, aRaster.getLetter(0, row), aRaster.getLetter(0, row)));
    	  aDrawableCrossTileComposite.addDrawable(new HalfLeftCrossTileDrawable(aSelectedWord, aRaster.getLetter(aRaster.getColumns()-1, row), aRaster.getLetter(aRaster.getColumns()-1, row)));
	  }
      // Add center
      for(int column = 0; column< aRaster.getColumns()-1; column++)
	  {
    	  for( int row = 0; row < aRaster.getRows()-1; row++)
    	  {
    		  aDrawableCrossTileComposite.addDrawable(new FullCrossTileDrawable(aSelectedWord, aRaster.getLetter(column, row), aRaster.getLetter(column+1, row), aRaster.getLetter(column, row+1), aRaster.getLetter(column+1, row+1)));
    	  }
	  }
      // Add letters
      for(int column = 0; column< aRaster.getColumns(); column++)
	  {
    	  for( int row = 0; row < aRaster.getRows(); row++)
    	  {
    		  aDrawableCrossTileComposite.addDrawable(new CharacterCrossTileDrawable(aSelectedWord, aRaster.getLetter(column, row)));
    	  }
	  }
      return aDrawableCrossTileComposite;
    }
}
